package com.wondersgroup.core.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wondersgroup.core.mapper.CompanyMapper;
import com.wondersgroup.core.model.Company;
import com.wondersgroup.core.resultmap.DTOCompany;

@Service
public class CompanyService {
	
	@Resource
	private CompanyMapper companyMapper;

	/**
	 * 根据企业名称或地址 经纬度 查询企业信息
	 * @param map
	 * @return
	 */
	public List<DTOCompany> queryCompany(Map<String, Object> map){
		int pageNum = 1;
				
		if 		(map.get("pageNum")!=null)
			pageNum = Integer.parseInt(map.get("pageNum").toString());
		int pageSize = 40;
		if 		(map.get("pageSize")!=null)

			pageSize = Integer.parseInt(map.get("pageSize").toString());
		PageHelper.startPage(pageNum, pageSize);
		List<DTOCompany> list=companyMapper.queryCompany(map);
       	return list;
        
	}
	/**
	 * 根据Id查询企业信息
	 * @param id
	 * @return
	 */
	public Company findById(Integer id){
		Company company=companyMapper.selectByPrimaryKey(id);
		return company;
	}

	
	/**
	 * 查询已经授权的企业
	 */
	public List<DTOCompany> queryAuthorizationCompany(int pageNum, int pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<DTOCompany> list =companyMapper.queryAuthorizationCompany();
		return list;
	}
	
	
	/**
	 * 查询未被授权的企业
	 */
	public List<DTOCompany> queryNotAuthorizationCompany(Map<String, Object> map){
		List<DTOCompany> list =companyMapper.queryNotAuthorizationCompany(map);
		return list;
	}
	
	
	/**
	 * 添加新的授权企业
	 * 根据企业ID修改企业状态为加入本平台
	 * 修改联系人姓名与电话
	 */
	public Integer addAuthorizationCompany(Map<String, Object> map){
		Integer condition=  companyMapper.addAuthorizationCompany(map);
		return condition;
	}
	
	
	 
	/**
	 * 修改企业信息
	 */
	public Integer updateCompany(Map<String, Object> map){
		 Integer condition=companyMapper.updateCompany(map);
		 return condition;
	}
	
	/**
	 * 通过ID修改DEL_FLAG为0:删除状态  修改COMPANY_ACCOUNT_STATUS为2：注销状态
	 * @param companyId
	 * @return
	 */
	public Integer deleteCompany(Integer companyId){
		Integer condition=companyMapper.deleteCompany(companyId);
		return condition;
	}
	
	
	public long getCountOfTraceableCompany() {
		return companyMapper.getCountOfTraceableCompany();
	}
}
